package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.eneity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "品牌列表")
@RestController
@RequestMapping("admin/product")
public class BaseTradeMarkController {

    @Autowired
    BaseTrademarkService baseTrademarkService;

    @ApiOperation("获取品牌列表")
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTradeMarkList(){

        List<BaseTrademark> list =
                baseTrademarkService.lambdaQuery().list();
        return Result.ok(list);
    }

    @ApiOperation("获取品牌分页列表")
    @GetMapping("/baseTrademark/{pn}/{ps}")
    public Result getBaseTradeMark(@PathVariable("pn") Long pn , @PathVariable("ps") Long ps){

        Page<BaseTrademark> page1 = new Page(pn,ps);
        Page<BaseTrademark> page = baseTrademarkService.page(page1);
        return Result.ok(page);
    }

    @ApiOperation("添加品牌")
    @PostMapping("/baseTrademark/save")
    public Result saveTradeMark(@RequestBody BaseTrademark baseTrademark){

        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("删除品牌")
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result deleteTradeMark(@PathVariable Long id){

        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("根据id获取品牌")
    @GetMapping("/baseTrademark/get/{id}")
    public Result getBaseTradeMarkById(@PathVariable("id") Long id){

        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    @ApiOperation("修改品牌")
    @PutMapping("/baseTrademark/update")
    public Result updateBaseTradeMarkById(@RequestBody BaseTrademark baseTrademark){

        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }


}
